package android.FiltrosJava;

import android.graphics.Bitmap;

public class MirrorHorizontal extends Filtro{
	public static int wid;
	public static int hei;
	
	public Bitmap applyFilter(Bitmap bmp) {
		int[] pixels;
		int height = bmp.getHeight();
		int width = bmp.getWidth();

		pixels = new int[height * width];
		bmp.getPixels(pixels, 0, width, 0, 0, width, height);

		int aux;
		int jump = 0;
		int lim = width / 2;
		int i= 0;
		int t1= i;
		int end= i + width-1;
		int t2= end;				
		
		while (i < width * height) {				
			
			aux = pixels[t1];
			pixels[t1] = pixels[t2];
			pixels[t2] = aux;
			t1++;
			t2--;
			i++;

			if (i == lim) {
				jump++;
				i = width * jump;
				end= i + width-1;
				t2= end;
				t1 = i;				
				lim += width;				
			}
		}
		
		bmp.setPixels(pixels, 0, width, 0, 0, width, height);		
		pixels = null;
		
		return bmp;
	}
	
	public int[] applyFilter(int[] pixels2) {
		/*int[] pixels;
		int height = bmp.getHeight();
		int width = bmp.getWidth();*/

		/*pixels = new int[height * width];
		bmp.getPixels(pixels, 0, width, 0, 0, width, height);
*/
		int aux;
		int jump = 0;
		int lim = Filtro.wid / 2;
		int i= 0;
		int t1= i;
		int end= i + Filtro.wid-1;
		int t2= end;				
		
		while (i < Filtro.wid * Filtro.hei) {				
			
			aux = pixels2[t1];
			pixels2[t1] = pixels2[t2];
			pixels2[t2] = aux;
			t1++;
			t2--;
			i++;

			if (i == lim) {
				jump++;
				i = Filtro.wid * jump;
				end= i + Filtro.wid-1;
				t2= end;
				t1 = i;				
				lim += Filtro.wid;				
			}
		}
		
		//bmp.setPixels(pixels, 0, width, 0, 0, width, height);		
		//pixels = null;
		
		return pixels2;
	}
}